package com.groenlid.mobileapp.UI;

import com.groenlid.mobileapp.MobApp;
import com.groenlid.mobileapp.R;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ImageAdapter extends BaseAdapter {

	private Context context;

    public ImageAdapter(Context context) {
    	this.context = context;
    }

    @Override
    public int getCount() {
        return mThumbIds.length;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    
    // create a new ImageView for each item referenced by the Adapter
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
    	LinearLayout linearLayout;
        if (convertView == null) {  // if it's not recycled, initialize some attributes
        	linearLayout = new LinearLayout(context);
        	linearLayout.setOrientation(LinearLayout.VERTICAL);
        	linearLayout.setGravity(Gravity.CENTER);
        	ImageView imageView;
            imageView = new ImageView(context);
            imageView.setLayoutParams(new GridView.LayoutParams(72, 72));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            //imageView.setPadding(8, 8, 8, 8);
            imageView.setImageResource(mThumbIds[position]);
            linearLayout.addView(imageView);
            TextView text = new TextView(context);
            text.setGravity(Gravity.CENTER);
            text.setText(mThumbString[position]);
            
            linearLayout.addView(text);
        } else {
        	linearLayout = (LinearLayout) convertView;
        }

        
        Log.i(MobApp.TAG,"Returning MenuView");
        return linearLayout;
    	
    	/*TextView textView;
    	if(convertView == null){
    		textView = new TextView(context);
    		textView.setLayoutParams(new GridView.LayoutParams(95,95));
    		textView.setPadding(8, 8, 8, 8);
    	} else {
    		textView = (TextView) convertView;
    	}
    	
    	textView.setBackgroundResource(mThumbIds[position]);
    	textView.setText(R.string.app_name);
    	textView.setGravity(Gravity.BOTTOM);
    	return textView;*/
    }

    // references to our images
    private Integer[] mThumbIds = {
            R.drawable.activity, 
            R.drawable.log,
            R.drawable.friends
    };
    
    private String[] mThumbString = {
    		"Start Activity",
    		"View Log",
    		"Friends"
    };

}